USE [master]
GO
/****** Object:  Database [ACS]    Script Date: 06/11/2009 07:21:03 ******/
CREATE DATABASE [ACS] ON  PRIMARY 
( NAME = N'ACS', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ACS.mdf' , SIZE = 2048KB , MAXSIZE = UNLIMITED, FILEGROWTH = 1024KB )
 LOG ON 
( NAME = N'ACS_log', FILENAME = N'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\ACS_log.ldf' , SIZE = 1024KB , MAXSIZE = 2048GB , FILEGROWTH = 10%)
GO
EXEC dbo.sp_dbcmptlevel @dbname=N'ACS', @new_cmptlevel=90
GO
IF (1 = FULLTEXTSERVICEPROPERTY('IsFullTextInstalled'))
begin
EXEC [ACS].[dbo].[sp_fulltext_database] @action = 'enable'
end
GO
ALTER DATABASE [ACS] SET ANSI_NULL_DEFAULT OFF 
GO
ALTER DATABASE [ACS] SET ANSI_NULLS OFF 
GO
ALTER DATABASE [ACS] SET ANSI_PADDING OFF 
GO
ALTER DATABASE [ACS] SET ANSI_WARNINGS OFF 
GO
ALTER DATABASE [ACS] SET ARITHABORT OFF 
GO
ALTER DATABASE [ACS] SET AUTO_CLOSE ON 
GO
ALTER DATABASE [ACS] SET AUTO_CREATE_STATISTICS ON 
GO
ALTER DATABASE [ACS] SET AUTO_SHRINK OFF 
GO
ALTER DATABASE [ACS] SET AUTO_UPDATE_STATISTICS ON 
GO
ALTER DATABASE [ACS] SET CURSOR_CLOSE_ON_COMMIT OFF 
GO
ALTER DATABASE [ACS] SET CURSOR_DEFAULT  GLOBAL 
GO
ALTER DATABASE [ACS] SET CONCAT_NULL_YIELDS_NULL OFF 
GO
ALTER DATABASE [ACS] SET NUMERIC_ROUNDABORT OFF 
GO
ALTER DATABASE [ACS] SET QUOTED_IDENTIFIER OFF 
GO
ALTER DATABASE [ACS] SET RECURSIVE_TRIGGERS OFF 
GO
ALTER DATABASE [ACS] SET  DISABLE_BROKER 
GO
ALTER DATABASE [ACS] SET AUTO_UPDATE_STATISTICS_ASYNC OFF 
GO
ALTER DATABASE [ACS] SET DATE_CORRELATION_OPTIMIZATION OFF 
GO
ALTER DATABASE [ACS] SET TRUSTWORTHY OFF 
GO
ALTER DATABASE [ACS] SET ALLOW_SNAPSHOT_ISOLATION OFF 
GO
ALTER DATABASE [ACS] SET PARAMETERIZATION SIMPLE 
GO
ALTER DATABASE [ACS] SET  READ_WRITE 
GO
ALTER DATABASE [ACS] SET RECOVERY SIMPLE 
GO
ALTER DATABASE [ACS] SET  MULTI_USER 
GO
ALTER DATABASE [ACS] SET PAGE_VERIFY CHECKSUM  
GO
ALTER DATABASE [ACS] SET DB_CHAINING OFF 


-- create all database objects


USE [ACS]
GO
/****** Object:  Table [dbo].[OutcomeGroup]    Script Date: 06/11/2009 07:23:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[OutcomeGroup](
	[GroupID] [int] IDENTITY(1,1) NOT NULL,
	[GroupName] [varchar](50) NULL,
 CONSTRAINT [PK_OutcomeGroup] PRIMARY KEY CLUSTERED 
(
	[GroupID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[ImportItem]    Script Date: 06/11/2009 07:23:30 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ImportItem](
	[ImportitemID] [bigint] IDENTITY(1,1) NOT NULL,
	[ItemName] [varchar](50) NOT NULL,
	[Date] [datetime] NOT NULL,
	[Amount] [varchar](50) NOT NULL,
 CONSTRAINT [PK_ImportItem] PRIMARY KEY CLUSTERED 
(
	[ImportitemID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[EuroCourse]    Script Date: 06/11/2009 07:23:29 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[EuroCourse](
	[Date] [datetime] NOT NULL,
	[Amount] [decimal](18, 2) NULL,
 CONSTRAINT [PK_EuroCourse] PRIMARY KEY CLUSTERED 
(
	[Date] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  Table [dbo].[User]    Script Date: 06/11/2009 07:23:34 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[User](
	[UserID] [int] IDENTITY(1,1) NOT NULL,
	[FristName] [varchar](50) NULL,
	[LastName] [varchar](50) NULL,
	[UserName] [varchar](50) NOT NULL,
	[Password] [varchar](50) NOT NULL,
 CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED 
(
	[UserID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[OutcomeItem]    Script Date: 06/11/2009 07:23:32 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[OutcomeItem](
	[ItemID] [int] IDENTITY(1,1) NOT NULL,
	[GroupID] [int] NOT NULL,
	[ItemName] [varchar](50) NULL,
 CONSTRAINT [PK_OutcomeItem] PRIMARY KEY CLUSTERED 
(
	[ItemID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
/****** Object:  Table [dbo].[UserOutcome]    Script Date: 06/11/2009 07:23:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[UserOutcome](
	[UserOutcomeID] [bigint] IDENTITY(1,1) NOT NULL,
	[UserID] [int] NOT NULL,
	[ItemID] [int] NOT NULL,
	[Date] [datetime] NOT NULL,
	[Amount] [decimal](18, 2) NOT NULL CONSTRAINT [DF_UserOutcome_Amount]  DEFAULT ((0)),
 CONSTRAINT [PK_UserOutcome] PRIMARY KEY CLUSTERED 
(
	[UserOutcomeID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object:  StoredProcedure [dbo].[UpdateEuro]    Script Date: 06/11/2009 07:23:28 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[UpdateEuro]
		@Date DateTime, 
		@Amount Decimal(18, 2)
AS
BEGIN
	DECLARE @STR_DATE VARCHAR(10);
	SET @STR_DATE = CONVERT(VARCHAR(10), @Date, 101);
	
	IF EXISTS (SELECT DATE FROM ACS.DBO.EUROCOURSE WHERE CONVERT(VARCHAR(10), DATE, 101) = @STR_DATE)
	BEGIN 
		UPDATE ACS.DBO.EUROCOURSE SET Amount = @Amount WHERE CONVERT(VARCHAR(10), DATE, 101) = @STR_DATE
	END
	ELSE
    BEGIN
        INSERT INTO ACS.DBO.EUROCOURSE (DATE, AMOUNT) VALUES (@STR_DATE, @Amount)
	END 
	
END
GO
/****** Object:  ForeignKey [FK_OutcomeItem_OutcomeGroup]    Script Date: 06/11/2009 07:23:32 ******/
ALTER TABLE [dbo].[OutcomeItem]  WITH CHECK ADD  CONSTRAINT [FK_OutcomeItem_OutcomeGroup] FOREIGN KEY([GroupID])
REFERENCES [dbo].[OutcomeGroup] ([GroupID])
GO
ALTER TABLE [dbo].[OutcomeItem] CHECK CONSTRAINT [FK_OutcomeItem_OutcomeGroup]
GO
/****** Object:  ForeignKey [FK_UserOutcome_OutcomeItem]    Script Date: 06/11/2009 07:23:36 ******/
ALTER TABLE [dbo].[UserOutcome]  WITH CHECK ADD  CONSTRAINT [FK_UserOutcome_OutcomeItem] FOREIGN KEY([ItemID])
REFERENCES [dbo].[OutcomeItem] ([ItemID])
GO
ALTER TABLE [dbo].[UserOutcome] CHECK CONSTRAINT [FK_UserOutcome_OutcomeItem]
GO
/****** Object:  ForeignKey [FK_UserOutcome_User]    Script Date: 06/11/2009 07:23:36 ******/
ALTER TABLE [dbo].[UserOutcome]  WITH CHECK ADD  CONSTRAINT [FK_UserOutcome_User] FOREIGN KEY([UserID])
REFERENCES [dbo].[User] ([UserID])
GO
ALTER TABLE [dbo].[UserOutcome] CHECK CONSTRAINT [FK_UserOutcome_User]
GO
